<template>
  <div class="article-details" v-if="pageData.id">
    <div class="padding-lr30 ">
      <div class="banner">
        <img :src="pageData.cover_picture" class="img-size-100" />
      </div>

      <div class="info-box">
        <div class="title">{{ pageData.title }}</div>
        <div class="origin">
          <text>作者 {{ pageData.author_name }}</text>
          <text>{{ pageData.created_at }}</text>
        </div>
        <div class="txt" v-if="pageData.profile">{{ pageData.profile }}</div>
      </div>

      <div class="product-box" v-if="pageData.product.length > 0">
        <div class="recommend">产品推荐</div>
        <div class="more">
          <a hover-class="none" url="/shop/productList/productList">
            查看更多 >
          </a>
        </div>
        <div class="list">
          <div
            class="row"
            v-for="(item, index) in pageData.product"
            :key="index"
          >
            <a
              :url="'/shop/productDetails/productDetails?id=' + item.id"
              hover-class="none"
            >
              <img class="image" :src="item.cover_picture" />
              <div class="title">{{ item.title }}</div>
              <div class="pric">
                <span>{{ item.lowest_price_name }}</span>
                <span class="pric-unit">美粉币</span>
              </div>
            </a>
          </div>
        </div>
      </div>
    </div>
    <div class="bottom"></div>
    <div class="details-box padding-lr30">
      <rich-text :nodes="pageData.describe | replaceImg"></rich-text>
    </div>
  </div>
</template>
<script>
import Share from "@/common/share";
export default {
  data() {
    return {
      pageData: {}
    };
  },
  onLoad(options) {
    if (options.id) {
      this.operatingDetail(options.id);
    }
    Share.getShareCode();
  },
  onShareAppMessage(res) {
    let { id, title, cover_picture } = this.pageData;
    return Share.getShareId({
      id,
      from: res.from,
      shareLink: `pages/articleDetails/articleDetails`,
      shareTitle: title,
      shareImgUrl: cover_picture
    });
  },
  methods: {
    operatingDetail(id) {
      this.$api.operatingDetail({ id }).then(res => {
        if (res.code == 200) {
          this.pageData = res.data;
        }
      });
    }
  }
};
</script>

<style lang="scss">
.article-details {
  color: #333;
  font-size: 26rpx;
  .img-size-100 {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
  .padding-lr30 {
    padding: 0 30rpx;
    box-sizing: border-box;
  }
  .banner {
    height: 285rpx;
    border-radius: 20rpx;
    overflow: hidden;
  }
  .info-box {
    margin: 20rpx 0 30rpx;
    overflow: hidden;
    border-bottom: 1px solid #bdbdbd;
    color: #999999;
    .title {
      height: 50rpx;
      line-height: 50rpx;
      margin-bottom: 20rpx;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
      color: #333333;
      font-size: 36rpx;
    }
    .origin {
      display: flex;
      justify-content: space-between;
      font-size: 24rpx;
      margin-bottom: 30rpx;
    }
    .txt {
      font-size: 26rpx;
      margin-bottom: 30rpx;
    }
  }
  .product-box {
    font-size: 28rpx;
    color: #333333;
    .list {
      width: 100%;
      padding-top: 19rpx;
      display: flex;
      justify-content: space-between;
      --n: 6;
      .row {
        width: calc(calc((220 / var(--n)) * 1%) - 20px);
        .image {
          width: 220rpx;
          height: 198rpx;
          border-radius: 8px;
        }
        .title {
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
          padding-top: 10rpx;
        }
        .pric {
          padding-top: 10rpx;
          color: #ff7900;
          font-size: 32rpx;
          font-weight: bold;
        }
        .pric-unit {
          color: #999999;
          font-size: 22rpx;
          padding-left: 5rpx;
          font-weight: normal;
        }
      }
    }

    .recommend,
    .more {
      width: 50%;
      float: left;
      box-sizing: border-box;
    }
    .more {
      font-size: 26rpx;
      color: #1772ff;
      text-align: right;
    }
  }
  .bottom {
    width: 100%;
    background-color: #f4f4f4;
    height: 20rpx;
    margin-top: 30rpx;
    margin-bottom: 30rpx;
  }
  .details-box {
    color: #333333;
    font-size: 26rpx;
    line-height: 40rpx;
  }
}
</style>
